package net.m510.autosurfer.aeoncard;

import java.net.URI;
import java.util.List;
import java.util.logging.Logger;

import net.m510.autosurfer.common.DocumentPostProcess;
import net.m510.autosurfer.core.Parameters;
import net.m510.autosurfer.core.utils.AnalyzeUtils;

import org.apache.http.NameValuePair;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.FormElement;

public class AeonCardLogin extends DocumentPostProcess {
	private static final Logger log = Logger.getLogger(AeonCardLogin.class.getName());
	private String memberId;
	private String password;

	public AeonCardLogin() {
		this(null,null);
	}
	public AeonCardLogin(CloseableHttpClient client, HttpClientContext context) {
		super(client, context);
		super.log = log;
	}
	@Override
	protected List<NameValuePair> getRequestParameters(Document doc) {
		FormElement form = doc.getAllElements().forms().get(0);
		Parameters p = Parameters.create(form);
		p.put("netMemberId", this.memberId);
		p.put("password", this.password);
		return p.asNameValueList();
	}

	@Override
	protected URI getUri(Document doc) {
		FormElement e = AnalyzeUtils.getFormElementByName(doc, "loginForm");
		return AnalyzeUtils.resolveURIByFormAction(context, e);
	}
	public String getMemberId() {
		return memberId;
	}
	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}